<template>
  <el-row :gutter="40" class="panel-group">
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="panelClick(1)">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="road" class-name="card-panel-icon"/>
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">通道使用情况</div>
          <count-to
            :start-val="0"
            :end-val="statistics.portNumber"
            :duration="3000"
            class="card-panel-num"
          />
          <span class="card-panel-num">/{{ statistics.portNumberMax }}</span>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="panelClick(2)">
        <div class="card-panel-icon-wrapper icon-guide">
          <svg-icon icon-class="shebei" class-name="card-panel-icon"/>
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">数据源总数</div>
          <count-to
            :start-val="0"
            :end-val="statistics.equipmentISNumber"
            :duration="300"
            class="card-panel-num"
          />
          <span class="card-panel-num">/{{ statistics.equipmentNumber }}</span>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" @click="panelClick(3)">
        <div class="card-panel-icon-wrapper icon-peoples">
          <svg-icon icon-class="shujudian" class-name="card-panel-icon"/>
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">数据采集点总数</div>
          <count-to
            :start-val="0"
            :end-val="statistics.dataElementISNumber"
            :duration="300"
            class="card-panel-num"
          /><span class="card-panel-num">/{{ statistics.dataElementNumber }}</span>
        </div>
      </div>
    </el-col>
    <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
      <div class="card-panel" :title="statistics.statusDetail" @click="panelClick(4)">
        <div class="card-panel-icon-wrapper icon-list">
          <svg-icon v-if="statistics.status === 2" icon-class="bug" class-name="card-panel-icon"/>
          <svg-icon v-else icon-class="example" class-name="card-panel-icon"/>
        </div>
        <div class="card-panel-description">
          <div class="card-panel-text">网关运行状态</div>
          <el-tag :type="statistics.status === 2?'danger':''">{{ transStatus(statistics.status) }} <i v-if="statistics.status === 2" class="el-icon-warning"></i></el-tag>
        </div>
      </div>
    </el-col>
  </el-row>
</template>

<script>
  import CountTo from "vue-count-to";

  export default {
    components: {
      CountTo
    },
    props: {
      statistics: {
        type: Object,
        'default': {}
      }
    },
    data() {
      return {};
    },
    created() {
    },
    methods: {
      transStatus(status) {
        let transStr = '';
        switch (status) {
          case 0:
            transStr = '未知';
            break;
          case 1:
            transStr = '运行中';
            break;
          case 2:
            transStr = '故障';
            break;
          case 3:
            transStr = '已停用';
            break;
          case 4:
            transStr = '备机启用中';
            break;
          case 5:
            transStr = '备机备用中';
            break;
        }
        return transStr;
      },
      panelClick(num) {
        if (this.$store.getters.user.level === 3) {
          return false
        }
        switch (num) {
          case 1:
            this.$router.push({
              name: 'collection'
            });
            break;
          case 2:
            this.$router.push({
              name: 'dataElement'
            });
            break;
          case 3:
            this.$router.push({
              name: 'dataElement'
            });
            break;
          case 4:
            if (this.statistics.status === 2) {
              this.$router.push({
                name: 'alarm-log'
              });
            } else {
              document.querySelector("#dis-table").scrollIntoView(true);
            }
            break;
        }
      }
    }
  };
</script>

<style lang="scss" scoped>
  .panel-group {
    .card-panel-col {
      margin-bottom: 32px;
    }

    .card-panel {
      height: 108px;
      cursor: pointer;
      font-size: 12px;
      position: relative;
      overflow: hidden;
      color: #666;
      background: #fff;
      box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
      border-color: rgba(0, 0, 0, 0.05);

      &:hover {
        .card-panel-icon-wrapper {
          color: #fff;
        }

        .icon-people {
          background: #eca350;
        }

        .icon-message,
        .icon-guide {
          background: #36a3f7;
        }

        .icon-money,
        .icon-nested,
        .icon-list {
          background: #f4516c;
        }

        .icon-shopping {
          background: #34bfa3;
        }

        .icon-peoples {
          background: #7115e9;
        }
      }

      .icon-people {
        color: #eca350;
      }

      .icon-peoples {
        color: #7115e9;
      }

      .icon-message,
      .icon-guide {
        color: #36a3f7;
      }

      .icon-money,
      .icon-nested,
      .icon-list {
        color: #f4516c;
      }

      .icon-shopping {
        color: #34bfa3;
      }

      .card-panel-icon-wrapper {
        float: left;
        margin: 14px 0 0 14px;
        padding: 16px;
        transition: all 0.38s ease-out;
        border-radius: 6px;
      }

      .card-panel-icon {
        float: left;
        font-size: 48px;
      }

      .card-panel-description {
        float: right;
        font-weight: bold;
        margin: 26px;
        margin-left: 0px;

        .card-panel-text {
          line-height: 18px;
          color: rgba(0, 0, 0, 0.45);
          font-size: 16px;
          margin-bottom: 12px;
        }

        .card-panel-num {
          font-size: 20px;
        }
      }
    }
  }
</style>
